def prostoe_ly(x):
    a=True
    for i in range(2, x):
        if x % i == 0:
            a=False
    return a
            
n=input().split()
n1=[]
num=0
wi=False
pr=[]
pr1=[]
if len(n)==3:
    for i in range(len(n)):
        if n[i]=="zero":
            n1.append(0)
        elif n[i]=="one":
            n1.append(1)
        elif n[i]=="two":
            n1.append(2)
        elif n[i]=="three":
            n1.append(3)
        elif n[i]=="four":
            n1.append(4)
        elif n[i]=="five":
            n1.append(5)
        elif n[i]=="six":
            n1.append(6)
        elif n[i]=="seven":
            n1.append(7)
        elif n[i]=="eight":
            n1.append(8)
        elif n[i]=="nine":
            n1.append(9)
        else:
            wi=True
    for k in range(3):
        if wi!=True:
            if k==0:
                num+=n1[k]*100
            if k==1:
                num+=n1[k]*10
            if k==2:
                num+=n1[k]
    for y in range(num+1,num+100):
        a=prostoe_ly(y)
        if a==True:
            pr.append(y)
    for q in range(1,num):
        a=prostoe_ly(q)
        if a==True:
            pr1.append(q)
else:
    wi=True
if wi==True:
    print("Wrong input")
else:
    if (num-pr1[-1])>(pr[0]-num):
        print(pr[0])
    else:
        print(pr1[-1])
